package quanlydoanra.themmoi;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;

import quanlydoanra.utils.truyXuatDatabase;
import utils.DateUtils;


import dbutil.ConnectDB;
import dbutil.DBUtils;
public class QuyetDinh {
	private int id;
	private String soQD;
	private java.util.Date ngayKyQD;
	private String nguoiKyQD;
	
	public QuyetDinh(){
	}
	public QuyetDinh(String soQD, java.util.Date ngayKyQD, String nguoiKyQD) {
		this.soQD = soQD;
		this.ngayKyQD = ngayKyQD;
		this.nguoiKyQD = nguoiKyQD;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSoQD() {
		return soQD;
	}

	public void setSoQD(String soQD) {
		this.soQD = soQD;
	}

	public java.util.Date getNgayKyQD() {
		return ngayKyQD;
	}

	public void setNgayKyQD(java.util.Date ngayKyQD) {
		this.ngayKyQD = ngayKyQD;
	}

	public String getNguoiKyQD() {
		return nguoiKyQD;
	}

	public void setNguoiKyQD(String nguoiKyQD) {
		this.nguoiKyQD = nguoiKyQD;
	}
	
	/**************************************
	 * Method name		: insertQuyetDinh
	 * Return type		: int
	 * Description		:
	 * Created date		: Aug 12, 2008
	 * Author			: Ngoc Diem
	 **************************************/
	public int insertQuyetDinh(){

		try{
		java.sql.Date sqlDate =  DateUtils.utilDateToSqlDate(this.ngayKyQD);	
		String sql2 = "insert into quyetdinh(soqd,ngaykyqd,nguoikyqd) values('"+this.soQD+"','"+sqlDate+"','"+this.nguoiKyQD+"')";
		System.out.println(sql2);
		int idQuyetDinh = truyXuatDatabase.insertData(sql2);
		
		if(idQuyetDinh == 1){
			String sql1 = "select * from quyetdinh where soqd = '"+this.soQD+"' and ngaykyqd = '"+this.ngayKyQD+"'and nguoikyqd = '"+this.nguoiKyQD+"'";
			ArrayList arr = ConnectDB.getDataTypeList(sql1);
			HashMap<String, Object> hash = (HashMap<String, Object>) arr.get(0);
			int id = Integer.parseInt(hash.get("id").toString());
			System.out.println("id muc dich "+id);
			this.id = id;
		}
		}
		catch(Exception ex){
			System.out.println("Loi ");
		}
	return this.id;
		
	}
	
	

}
